package com.ysqcould.web.controller.allocation;

import com.ysqcould.allocation.domain.Navigation;
import com.ysqcould.allocation.domain.Submodule;
import com.ysqcould.allocation.service.ISubmoduleService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 移动办公子模块名称Controller
 * 
 * @author jcd
 * @date 2022-09-19
 */
@RestController
@RequestMapping("/allocation/submodule")
public class SubmoduleController extends BaseController
{
    @Autowired
    private ISubmoduleService submoduleService;

    /**
     * 查询移动办公子模块名称列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:submodule:list')")
    @GetMapping("/list")
    public TableDataInfo list(Submodule submodule)
    {
        startPage();
        List<Submodule> list = submoduleService.selectSubmoduleList(submodule);
        return getDataTable(list);
    }

    /**
     * 导出移动办公子模块名称列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:submodule:export')")
    @Log(title = "移动办公子模块名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Submodule submodule)
    {
        List<Submodule> list = submoduleService.selectSubmoduleList(submodule);
        ExcelUtil<Submodule> util = new ExcelUtil<Submodule>(Submodule.class);
        util.exportExcel(response, list, "移动办公子模块名称数据");
    }

    /**
     * 获取移动办公子模块名称详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:submodule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(submoduleService.selectSubmoduleById(id));
    }

    /**
     * 新增移动办公子模块名称
     */
    @PreAuthorize("@ss.hasPermi('allocation:submodule:add')")
    @Log(title = "移动办公子模块名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Submodule submodule)
    {
        return toAjax(submoduleService.insertSubmodule(submodule));
    }

    /**
     * 修改移动办公子模块名称
     */
    @PreAuthorize("@ss.hasPermi('allocation:submodule:edit')")
    @Log(title = "移动办公子模块名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Submodule submodule)
    {
        return toAjax(submoduleService.updateSubmodule(submodule));
    }

    /**
     * 删除移动办公子模块名称
     */
    @PreAuthorize("@ss.hasPermi('allocation:submodule:remove')")
    @Log(title = "移动办公子模块名称", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(submoduleService.deleteSubmoduleByIds(ids));
    }

    @Log(title = "修改移动办公模块状态",businessType = BusinessType.UPDATE)
    @PutMapping("changeStatus")
    public AjaxResult changeStatus(@RequestBody Submodule submodule){
        return toAjax(submoduleService.updateSubmoduleStatus(submodule));
    }
}
